from django.db import models
from django.utils import timezone
import datetime

class Article(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    tag = models.CharField(max_length=30, default='', blank=False)
    create_time = models.PositiveIntegerField(default=0, verbose_name='新增时间')
    update_time = models.PositiveIntegerField(default=0, verbose_name='更新时间')
    delete_time = models.PositiveIntegerField(default=0, verbose_name='删除时间')

    def __str__(self):
        return self.title

 # 这是一个示例方法，你可以根据需要定义其他方法
    def save(self, *args, **kwargs):
        if not self.id:
            # 新建对象，设置创建时间
            self.create_time = int(datetime.datetime.now().timestamp())
        else:
            # 更新对象，设置更新时间
            self.update_time = int(datetime.datetime.now().timestamp())
        super(Article, self).save(*args, **kwargs)


    def delete(self, *args, **kwargs):
        # 这里可以添加自定义的删除逻辑
        super().delete(*args, **kwargs)

    def soft_delete(self):
        # 设置 delete_time 为当前时间戳
        self.delete_time = int(datetime.datetime.now().timestamp())
        self.save()

    #class Meta:
    #    abstract = True